package main;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * @author Holly Beach
 * @version 12/3/11
 * 
 * Daniel Anderson added clone, toString, and equals.
 * Cristopher updated some methods
 * 
 * This class contains data regarding users of a system,
 * including user ID, name, and roles.
 * Class Invariant: User IDs are unique
 */
public class User implements Serializable {

	private static final long serialVersionUID = 1900947697999116694L;
	private String my_id;
	private String my_name;
	private ArrayList<Roles> my_roles;
	
	/**
	 * @author Holly Beach
	 * 
	 * Cristopher added business rule @1 and changed parameters
	 * 
	 * @version 12/3/11
	 * PRECONDITION: an_id is unique, no other User object has getID() == an_id.
	 */
	public User(String an_id, String a_name) {
		my_id = an_id;
		my_name = a_name;
		my_roles = new ArrayList<Roles>();
		my_roles.add(Roles.AUTHOR);
	}//end of constructor
	
	/**@return The ID of the user*/
	public String getID() {
		return my_id;
	}//end of getID
	
	/**@return The Name of the user.*/
	public String getName() {
		return my_name;
	}//end of getName
	
	/**@return A list of roles of the user*/
	public ArrayList<Roles> getRoles() {
		return my_roles;
	}//end of getRoles
	
	/**
	 * @author Holly Beach
	 * 
	 * Cristopher updated to remove precondition
	 * 
	 * @version 11/30/11
	 */
	public void addRole(Roles a_role) {
		if(!my_roles.contains(a_role)){
			my_roles.add(a_role);
		}
	}//end of addRole

	//TODO remove this?
	/**
	 * A method similar to clone that returns a copy
	 * of a User, but with a fresh empty Role list.
	 * NOTE: This is no longer used, but will be kept
	 * 		in case we need it later.
	 * @return A new User
	 *
	public User cleanUserClone() {
		User u = new User(my_id, my_name);
		return u;
	} //end of cleanUserClone()*/

	@Override
	public boolean equals(Object the_obj) {
		return my_id.equals(the_obj.toString());
	}//end of equals
	
	/**
	 * IDs are always unique to User, so toString
	 * just returns the UserID.
	 */
	@Override
	public String toString() {
		return getID();
	}//end of toString
}
